/*
 * File:   api_buzzer.c
 * Author: Ich
 *
 * Created on 12. Januar 2014, 16:59
 *
 */

#include <plib.h>
#include "api_buzzer.h"
#include "driver_buzzer.h"
#include "driver_timer.h"
/*******************************************************************************
 *  private preprocessing definitions
 */
#define CONV_FREQ_TO_TIMERPERIOD(freq)         (38400000 / 32 / freq)
#define CONV_LOUD_TO_TIMERPERIOD(loud)         (38400000 / 32 / 2000 * loud / 200)
 /*******************************************************************************
 *  private variables
 */

// Type in the buzzer loudness [0..100 %]. Every frequency is On for 200 msec.
// no longer than DmaGetMaxTxferSize() bytes: this is the maximum DMA transfer size
static const UINT16 BUZZER_SAYNO[]=
{
    CONV_LOUD_TO_TIMERPERIOD(100),
    CONV_LOUD_TO_TIMERPERIOD(10),
    CONV_LOUD_TO_TIMERPERIOD(10),
    CONV_LOUD_TO_TIMERPERIOD(10),
    0
};

// Type in the buzzer loudness [0..100 %]. Every frequency is On for 200 msec.
// no longer than DmaGetMaxTxferSize() bytes: this is the maximum DMA transfer size
static const UINT16 BUZZER_SAYYES[]=
{
    CONV_LOUD_TO_TIMERPERIOD(10),
    CONV_LOUD_TO_TIMERPERIOD(100),
    0
};

// Type in the buzzer loudness [0..100 %]. Every frequency is On for 200 msec.
// no longer than DmaGetMaxTxferSize() bytes: this is the maximum DMA transfer size
static const UINT16 BUZZER_SAYSIGNAL[]=
{
    CONV_LOUD_TO_TIMERPERIOD(100),
    0
};

/*******************************************************************************
 *  private functions
 */

 /*******************************************************************************
 *  public variables (defined by external)
 */


/*******************************************************************************
 *  public functions
 */

void apiBuzzer_init (void)
{
    drvBuzzer_init();
}


void apiBuzzer_sayYes (void)
{
    drvBuzzer_setSignalWithDMA(BUZZER_SAYYES, sizeof(BUZZER_SAYYES)/sizeof(BUZZER_SAYYES[0]));
}


void apiBuzzer_sayNo (void)
{
    drvBuzzer_setSignalWithDMA(BUZZER_SAYNO, sizeof(BUZZER_SAYNO)/sizeof(BUZZER_SAYNO[0]));
}


void apiBuzzer_saySignal (void)
{
    drvBuzzer_setSignalWithDMA(BUZZER_SAYSIGNAL, sizeof(BUZZER_SAYSIGNAL)/sizeof(BUZZER_SAYSIGNAL[0]));
}



